package org.sdp.pearproject.controller;


import org.sdp.pearproject.controller.custom.*;
import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;

import java.util.List;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: TaskController
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-18
 * @Version: 1.0
 * Table: pear_task
 * Comment:
 * 任务表
 */
@RestController
@RequestMapping(value = "/task")
public class TaskController extends TaskCustomController {
    static {
        addRequestClass("task", "add", "taskController", TaskController.class, TaskAddRequest.class);
        addRequestClass("task", "add_encrypt", "taskController", TaskController.class, TaskAddRequest.class);

        addRequestClass("task", "update", "taskController", TaskController.class, TaskUpdateRequest.class);
        addRequestClass("task", "update_encrypt", "taskController", TaskController.class, TaskUpdateRequest.class);

        addRequestClass("task", "delete", "taskController", TaskController.class, TaskDeleteRequest.class);
        addRequestClass("task", "delete_encrypt", "taskController", TaskController.class, TaskDeleteRequest.class);

        addRequestClass("task", "query", "taskController", TaskController.class, TaskQueryRequest.class);
        addRequestClass("task", "query_encrypt", "taskController", TaskController.class, TaskQueryRequest.class);

        addRequestClass("task", "list", "taskController", TaskController.class, TaskQueryRequest.class);
        addRequestClass("task", "list_encrypt", "taskController", TaskController.class, TaskQueryRequest.class);

        addRequestClass("task", "count", "taskController", TaskController.class, TaskQueryRequest.class);
        addRequestClass("task", "count_encrypt", "taskController", TaskController.class, TaskQueryRequest.class);

        addRequestClass("task", "stat", "taskController", TaskController.class, TaskQueryRequest.class);
        addRequestClass("task", "stat_encrypt", "taskController", TaskController.class, TaskQueryRequest.class);

    }

    @PostMapping("/add")
    public Integer addTask(@MixRequestBody TaskAddRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("task", "add", request, callFromEncrypt);
        return super.addTask(request);
    }

    @PostMapping("/add_encrypt")
    public String addTaskEncrypt(@MixRequestBody String strRequest) throws Exception {
        TaskAddRequest request = (TaskAddRequest) super.decrypt("task", "add_encrypt", strRequest, TaskAddRequest.class);
        Integer result = addTask(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/update")
    public Integer updateTask(@MixRequestBody TaskUpdateRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("task", "update", request, callFromEncrypt);
        return super.updateTask(request);
    }

    @PostMapping("/update_encrypt")
    public String updateTaskEncrypt(@MixRequestBody String strRequest) throws Exception {
        TaskUpdateRequest request = (TaskUpdateRequest) super.decrypt("task", "update_encrypt", strRequest, TaskUpdateRequest.class);
        Integer result = updateTask(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/delete")
    public Integer deleteTask(@MixRequestBody TaskDeleteRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("task", "delete", request, callFromEncrypt);
        return super.deleteTask(request);
    }

    @PostMapping("/delete_encrypt")
    public String deleteTaskEncrypt(@MixRequestBody String strRequest) throws Exception {
        TaskDeleteRequest request = (TaskDeleteRequest) super.decrypt("task", "delete_encrypt", strRequest, TaskDeleteRequest.class);
        Integer result = deleteTask(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/query")
    public TaskQueryResponse queryTask(@MixRequestBody TaskQueryRequest request, Integer callFromEncrypt) throws Exception {
      super.fixRequest("task", "query", request, callFromEncrypt);
      return super.queryTask(request);
    }

    @PostMapping("/query_encrypt")
    public String queryTaskEncrypt(@MixRequestBody String strRequest) throws Exception {
        TaskQueryRequest request = (TaskQueryRequest) super.decrypt("task", "query_encrypt", strRequest, TaskQueryRequest.class);
        TaskQueryResponse result = queryTask(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/list")
    public List<TaskQueryResponse> listTask(@MixRequestBody TaskQueryRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("task", "list", request, callFromEncrypt);
        if (super.needTotal("task", "list", request)) {
            super.setTotal("task", "list", request, super.countTask(request));
        }
        return super.listTask(request);
    }

    @PostMapping("/list_encrypt")
    public String listTaskEncrypt(@MixRequestBody String strRequest) throws Exception {
        TaskQueryRequest request = (TaskQueryRequest) super.decrypt("task", "list_encrypt", strRequest, TaskQueryRequest.class);
        List<TaskQueryResponse> result = listTask(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/count")
    public Integer countTask(@MixRequestBody TaskQueryRequest request, Integer callFromEncrypt) throws Exception {
      super.fixRequest("task", "count", request, callFromEncrypt);
      return super.countTask(request);
    }


    @PostMapping("/count_encrypt")
    public String countTaskEncrypt(@MixRequestBody String strRequest) throws Exception {
        TaskQueryRequest request = (TaskQueryRequest) super.decrypt("task", "count_encrypt", strRequest, TaskQueryRequest.class);
        Integer result = countTask(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/stat")
    public BaseStatResponse statTask(@MixRequestBody TaskQueryRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("task", "stat", request, callFromEncrypt);
        return super.statTask(request);
    }

    @PostMapping("/stat_encrypt")
    public String statTaskEncrypt(@MixRequestBody String strRequest) throws Exception {
        TaskQueryRequest request = (TaskQueryRequest) super.decrypt("task", "stat_encrypt", strRequest, TaskQueryRequest.class);
        BaseStatResponse result = statTask(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }


}
